package com.qingneng.budget.dao;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.common.util.PaginatedList;
import com.qingneng.budget.util.PaginationBean;
import com.qingneng.budget.util.PaginationContext;
import com.qingneng.budget.vo.ContractInfo;

public class ContractInfoDaoImpl extends SqlMapClientDaoSupport implements IContractInfoDao{

	public List queryContractInfo() {
		List list = getSqlMapClientTemplate().queryForList("qn_db_contractinfo.select_contractinfo_sql");
		return list;
	}

	public Integer queryTotalCount() {
		Integer total =  (Integer)getSqlMapClientTemplate().queryForObject("qn_db_contractinfo.select_contractinfo_count_sql");	
		return total;
	}

	public void insertContractInfo(ContractInfo bean) {
		 this.getSqlMapClientTemplate().insert("qn_db_contractinfo.insert_contractinfo_sql", bean);
	}
	
	public void deleteContractInfo(ContractInfo bean) {
		 this.getSqlMapClientTemplate().delete("qn_db_contractinfo.delete_contractinfo_sql", bean);
	}

	public void update(ContractInfo bean) {
		 this.getSqlMapClientTemplate().update("qn_db_contractinfo.update_contractinfo_sql", bean);
		
	}

	public List queryContractInfo(ContractInfo contractInfo) {
		List list = getSqlMapClientTemplate().queryForList("qn_db_contractinfo.select_contractinfo_sql",contractInfo);
		return list;
	}

	public Integer queryTotalCount(ContractInfo contractInfo) {
		Integer total =  (Integer)getSqlMapClientTemplate().queryForObject("qn_db_contractinfo.select_contractinfo_count_sql",contractInfo);	
		return total;
	}

	public List queryMainContractInfo(ContractInfo contractInfo) {
		List list = new ArrayList();
		ThreadLocal pagination = new ThreadLocal();	
		PaginationBean pageBean = PaginationContext.getPaginationBean();
		
		/*PaginatedList queryForPaginatedList = getSqlMapClientTemplate().queryForPaginatedList("qn_db_contractinfo.select_main_contractinfo_sql",
				contractInfo,pageBean.getPageSize());
	
		
		int pageNo = pageBean.getPageNo();
		if(pageNo==1){
			queryForPaginatedList.isFirstPage();
		}
					
		boolean nextPage = queryForPaginatedList.nextPage();
		int index = queryForPaginatedList.getPageIndex();
		Iterator iterator = queryForPaginatedList.iterator();
		while(iterator.hasNext()){
			 Object object = iterator.next();
			 list.add(object);
		}*/
		contractInfo.setPageBean(pageBean);
		//int startIndex = pageBean.getStart();
		//int pageSize = pageBean.getPageSize();
		list = getSqlMapClientTemplate().queryForList("qn_db_contractinfo.select_main_contractinfo_sql",contractInfo);
		
		//int pageNo = pageBean.getPageNo();
		//int pageSize = pageBean.getPageSize();
			
		return list;			
		//return getSqlMapClientTemplate().queryForList("qn_db_contractinfo.select_main_contractinfo_sql",contractInfo,);
	}

	public List getContractInfoByStatus(Map paramMap) {
		List list = getSqlMapClientTemplate().queryForList("qn_db_contractinfo.select_aduit_contractinfo_sql",paramMap);
		return list;
	}


}
